package com.haipumi.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.haipumi.beans.haipumi_reply;
import com.haipumi.dao.DBHelper;
import com.haipumi.dao.IBackTaskReplyDao;

public class BackTaskReplyDaoImpl implements IBackTaskReplyDao {
	DBHelper db=new DBHelper();
	@Override
	public List<haipumi_reply> findAllTaskReply() {
		String sql="select * from haipumi_reply ";
		List<haipumi_reply> replylist=null;
		try {
			replylist=db.finds(sql, null, haipumi_reply.class);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return replylist;
	}
	@Override
	public int countTaskReply() {
		String sql="select count(*) from haipumi_reply ";
		int r=0;
		try {
			r=(int) db.findDouble(sql, null);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return r;
	}
	@Override
	public haipumi_reply editReply(haipumi_reply reply) {
		String sql="update haipumi_reply set rcontent=? ,rsupportid=? where rid=? ";
		List<Object>params=new ArrayList<Object>();
		params.add(reply.getRcontent());
		params.add(reply.getRsupportid());
		params.add(reply.getRid());
		
		int result=0;
		
		try {
			result=db.doUpdate(sql, params);
			if(result>0){
				return reply;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return null;
	}
	@Override
	public haipumi_reply findreply(String rid) {
		String sql="select * from haipumi_reply where rid=? ";
		List<Object>params=new ArrayList<Object>();
		params.add(rid);
		haipumi_reply backreply=null;
		List<haipumi_reply>backreplylist=null;
		try {
			backreplylist=db.finds(sql, params, haipumi_reply.class);
			if(!backreplylist.isEmpty()){
				backreply=backreplylist.get(0);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return backreply;
	}

}
